package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.corona.Game;
import com.corona.game.util.TextureCache;
import com.corona.game.util.audio.AudioLoader;
import java.util.Locale;

/* compiled from: Battle.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/GainExpAnimationGen2.class */
class GainExpAnimationGen2 extends Action {
    Pokemon pokemon;
    int targetIndex = 0;
    int timer = 0;
    boolean leveledUp = false;
    Sound xpGainSound = AudioLoader.loadSound("sounds/xp-gain1.ogg");
    Sound levelUpSound = AudioLoader.loadSound("sounds/xp-levelup1.ogg");

    public GainExpAnimationGen2(Pokemon pokemon, Action nextAction) {
        super(new Object[0]);
        this.pokemon = pokemon;
        this.nextAction = nextAction;
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        this.timer = 0;
        int currentLevelXp = this.pokemon.calcExpForLevel(this.pokemon.level);
        this.targetIndex = (int) (67.0f * (((float) (this.pokemon.exp - currentLevelXp)) / ((float) (this.pokemon.calcExpForLevel(this.pokemon.level + 1) - currentLevelXp))));
        this.xpGainSound.play();
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        if (this.timer < 9) {
            this.timer++;
            return;
        }
        if (DrawFriendlyHealthGen2.xpBarIndex == 67) {
            this.xpGainSound.stop();
            this.levelUpSound.play();
            this.pokemon.gainLevel(1);
            game.battle.drawAction.drawFriendlyHealthAction.layer = Action.Layer.gui_104;
            game.actionStack.remove(game.battle.drawAction.drawFriendlyHealthAction);
            game.insertAction(game.battle.drawAction.drawFriendlyHealthAction);
        }
        if (DrawFriendlyHealthGen2.xpBarIndex < 67) {
            if (DrawFriendlyHealthGen2.xpBarIndex >= this.targetIndex) {
                this.xpGainSound.stop();
                this.xpGainSound.dispose();
                this.levelUpSound.stop();
                this.levelUpSound.dispose();
                game.actionStack.remove(this);
                Action action = new Action(new Object[0]);
                if (this.leveledUp) {
                    action.append(new DisplayText.Clear(game, new WaitFrames(game, 2, new ShowLevelUpStats(null))));
                }
                action.append(this.nextAction);
                game.insertAction(action);
            }
            DrawFriendlyHealthGen2.xpBarIndex++;
        } else if (DrawFriendlyHealthGen2.xpBarIndex < 76) {
            DrawFriendlyHealthGen2.xpBarIndex++;
        } else {
            this.leveledUp = true;
            game.actionStack.remove(this);
            Action action2 = new WaitFrames(game, 13, new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, this.pokemon.nickname.toUpperCase(Locale.ROOT) + " grew to level " + this.pokemon.level + "!", "fanfare1.ogg", true, true, (Action) new CheckMovesLearned(this.pokemon, new RunCode(()
            /*  JADX ERROR: Method code generation error
                jadx.core.utils.exceptions.CodegenException: Error generate insn: 0x00fa: CONSTRUCTOR  (r0v29 'action2' com.corona.game.Action) =
                  (r27v0 'game' com.corona.Game A[D('game' com.corona.Game)])
                  (13 int)
                  (wrap: com.corona.game.DisplayText$Clear : 0x00f7: CONSTRUCTOR  (r4v1 com.corona.game.DisplayText$Clear A[REMOVE]) =
                  (r27v0 'game' com.corona.Game A[D('game' com.corona.Game)])
                  (wrap: com.corona.game.WaitFrames : 0x00f4: CONSTRUCTOR  (r7v1 com.corona.game.WaitFrames A[REMOVE]) =
                  (r27v0 'game' com.corona.Game A[D('game' com.corona.Game)])
                  (3 int)
                  (wrap: com.corona.game.DisplayText : 0x00f1: CONSTRUCTOR  (r11v0 com.corona.game.DisplayText A[REMOVE]) =
                  (r27v0 'game' com.corona.Game A[D('game' com.corona.Game)])
                  (wrap: java.lang.String : ?: STR_CONCAT
                  (wrap: java.lang.String : 0x00b6: INVOKE
                  (wrap: java.lang.String : 0x00b0: IGET
                  (wrap: com.corona.game.Pokemon : 0x00ad: IGET
                  (r26v0 'this' com.corona.game.GainExpAnimationGen2 A[D('this' com.corona.game.GainExpAnimationGen2), IMMUTABLE_TYPE, THIS])
                 com.corona.game.GainExpAnimationGen2.pokemon com.corona.game.Pokemon)
                 com.corona.game.Pokemon.nickname java.lang.String)
                  (wrap: java.util.Locale : 0x00b3: SGET   java.util.Locale.ROOT java.util.Locale)
                 type: VIRTUAL call: java.lang.String.toUpperCase(java.util.Locale):java.lang.String)
                  (" grew to level ")
                  (wrap: int : 0x00c5: IGET
                  (wrap: com.corona.game.Pokemon : 0x00c2: IGET
                  (r26v0 'this' com.corona.game.GainExpAnimationGen2 A[D('this' com.corona.game.GainExpAnimationGen2), IMMUTABLE_TYPE, THIS])
                 com.corona.game.GainExpAnimationGen2.pokemon com.corona.game.Pokemon)
                 com.corona.game.Pokemon.level int)
                  ("!")
                )
                  ("fanfare1.ogg")
                  true
                  true
                  (wrap: com.corona.game.Action : ?: CAST (com.corona.game.Action) (wrap: com.corona.game.CheckMovesLearned : 0x00ee: CONSTRUCTOR  (r18v0 com.corona.game.CheckMovesLearned A[REMOVE]) =
                  (wrap: com.corona.game.Pokemon : 0x00dc: IGET  (r20v1 com.corona.game.Pokemon A[REMOVE]) =
                  (r26v0 'this' com.corona.game.GainExpAnimationGen2 A[D('this' com.corona.game.GainExpAnimationGen2), IMMUTABLE_TYPE, THIS])
                 com.corona.game.GainExpAnimationGen2.pokemon com.corona.game.Pokemon)
                  (wrap: com.corona.game.RunCode : 0x00eb: CONSTRUCTOR  (r21v0 com.corona.game.RunCode A[REMOVE]) =
                  (wrap: java.lang.Runnable : 0x00e5: INVOKE_CUSTOM (r23v1 java.lang.Runnable A[REMOVE]) =
                  (r26v0 'this' com.corona.game.GainExpAnimationGen2 A[D('this' com.corona.game.GainExpAnimationGen2), DONT_INLINE, IMMUTABLE_TYPE, THIS])
                  (r27v0 'game' com.corona.Game A[D('game' com.corona.Game), DONT_INLINE])

                 handle type: INVOKE_DIRECT
                 lambda: java.lang.Runnable.run():void
                 call insn: ?: INVOKE  (r23 I:com.corona.game.GainExpAnimationGen2), (r24 I:com.corona.Game) type: DIRECT call: com.corona.game.GainExpAnimationGen2.lambda$step$0(com.corona.Game):void)
                  (r26v0 'this' com.corona.game.GainExpAnimationGen2 A[D('this' com.corona.game.GainExpAnimationGen2), IMMUTABLE_TYPE, THIS])
                 call: com.corona.game.RunCode.<init>(java.lang.Runnable, com.corona.game.Action):void type: CONSTRUCTOR)
                 call: com.corona.game.CheckMovesLearned.<init>(com.corona.game.Pokemon, com.corona.game.Action):void type: CONSTRUCTOR))
                 call: com.corona.game.DisplayText.<init>(com.corona.Game, java.lang.String, java.lang.String, boolean, boolean, com.corona.game.Action):void type: CONSTRUCTOR)
                 call: com.corona.game.WaitFrames.<init>(com.corona.Game, int, com.corona.game.Action):void type: CONSTRUCTOR)
                 call: com.corona.game.DisplayText.Clear.<init>(com.corona.Game, com.corona.game.Action):void type: CONSTRUCTOR)
                 call: com.corona.game.WaitFrames.<init>(com.corona.Game, int, com.corona.game.Action):void type: CONSTRUCTOR in method: com.corona.game.GainExpAnimationGen2.step(com.corona.Game):void, file: pokewilds.jar:com/pkmngen/game/GainExpAnimationGen2.class
                	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:285)
                	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:248)
                	at jadx.core.codegen.RegionGen.makeSimpleBlock(RegionGen.java:105)
                	at jadx.core.dex.nodes.IBlock.generate(IBlock.java:15)
                	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                	at jadx.core.dex.regions.Region.generate(Region.java:35)
                	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                	at jadx.core.codegen.RegionGen.makeRegionIndent(RegionGen.java:94)
                	at jadx.core.codegen.RegionGen.makeIf(RegionGen.java:151)
                	at jadx.core.codegen.RegionGen.connectElseIf(RegionGen.java:170)
                	at jadx.core.codegen.RegionGen.makeIf(RegionGen.java:147)
                	at jadx.core.dex.regions.conditions.IfRegion.generate(IfRegion.java:137)
                	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                	at jadx.core.dex.regions.Region.generate(Region.java:35)
                	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                	at jadx.core.dex.regions.Region.generate(Region.java:35)
                	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                	at jadx.core.dex.regions.Region.generate(Region.java:35)
                	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                	at jadx.core.codegen.MethodGen.addRegionInsns(MethodGen.java:261)
                	at jadx.core.codegen.MethodGen.addInstructions(MethodGen.java:254)
                	at jadx.core.codegen.ClassGen.addMethodCode(ClassGen.java:349)
                	at jadx.core.codegen.ClassGen.addMethod(ClassGen.java:302)
                	at jadx.core.codegen.ClassGen.lambda$addInnerClsAndMethods$2(ClassGen.java:271)
                	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
                	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
                	at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
                	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:261)
                Caused by: java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
                	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
                	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
                	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
                	at java.base/java.util.Objects.checkIndex(Objects.java:385)
                	at java.base/java.util.ArrayList.get(ArrayList.java:427)
                	at jadx.core.codegen.InsnGen.makeInlinedLambdaMethod(InsnGen.java:909)
                	at jadx.core.codegen.InsnGen.makeInvokeLambda(InsnGen.java:814)
                	at jadx.core.codegen.InsnGen.makeInvoke(InsnGen.java:756)
                	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:397)
                	at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:141)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:120)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:104)
                	at jadx.core.codegen.InsnGen.generateMethodArguments(InsnGen.java:976)
                	at jadx.core.codegen.InsnGen.makeConstructor(InsnGen.java:711)
                	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:393)
                	at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:141)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:120)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:104)
                	at jadx.core.codegen.InsnGen.generateMethodArguments(InsnGen.java:976)
                	at jadx.core.codegen.InsnGen.makeConstructor(InsnGen.java:711)
                	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:393)
                	at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:141)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:120)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:104)
                	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:320)
                	at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:141)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:120)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:104)
                	at jadx.core.codegen.InsnGen.generateMethodArguments(InsnGen.java:976)
                	at jadx.core.codegen.InsnGen.makeConstructor(InsnGen.java:711)
                	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:393)
                	at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:141)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:120)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:104)
                	at jadx.core.codegen.InsnGen.generateMethodArguments(InsnGen.java:976)
                	at jadx.core.codegen.InsnGen.makeConstructor(InsnGen.java:711)
                	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:393)
                	at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:141)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:120)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:104)
                	at jadx.core.codegen.InsnGen.generateMethodArguments(InsnGen.java:976)
                	at jadx.core.codegen.InsnGen.makeConstructor(InsnGen.java:711)
                	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:393)
                	at jadx.core.codegen.InsnGen.addWrappedArg(InsnGen.java:141)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:120)
                	at jadx.core.codegen.InsnGen.addArg(InsnGen.java:104)
                	at jadx.core.codegen.InsnGen.generateMethodArguments(InsnGen.java:976)
                	at jadx.core.codegen.InsnGen.makeConstructor(InsnGen.java:711)
                	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:393)
                	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:278)
                	... 27 more
                */
            /*
            // Method dump skipped, instructions count: 441
            */
            throw new UnsupportedOperationException("Method not decompiled: com.corona.game.GainExpAnimationGen2.step(com.corona.Game):void");
        }

        /* compiled from: Battle.java */
        /* loaded from: pokewilds.jar:com/pkmngen/game/GainExpAnimationGen2$ShowLevelUpStats.class */
        static class ShowLevelUpStats extends Action {
            public Action.Layer layer = Action.Layer.gui_103;
            public int timer = 0;
            String[] allStats = {"attack", "defense", "specialAtk", "specialDef", "speed"};
            Sprite bgSprite = new Sprite(TextureCache.get(Gdx.files.internal("battle/gsc/levelup_stats_screen1.png")));

            public ShowLevelUpStats(Action nextAction) {
                super(new Object[0]);
                this.nextAction = nextAction;
            }

            @Override // com.corona.game.Action
            public String getCamera() {
                return "gui";
            }

            @Override // com.corona.game.Action
            public Action.Layer getLayer() {
                return this.layer;
            }

            @Override // com.corona.game.Action
            public void step(Game game) {
                game.uiBatch.draw(this.bgSprite, 0.0f, 0.0f);
                int i = 0;
                String[] strArr = this.allStats;
                for (String stat : strArr) {
                    String text = stat.toUpperCase(Locale.ROOT);
                    if (text.equals("SPECIALATK")) {
                        text = "SPCL.ATK";
                    } else if (text.equals("SPECIALDEF")) {
                        text = "SPCL.DEF";
                    }
                    char[] textArray = text.toCharArray();
                    for (int j = 0; j < textArray.length; j++) {
                        game.uiBatch.draw(game.transparentDict.get(Character.valueOf(textArray[j])), (float) (88 + (8 * j)), (float) (128 - (8 * i)));
                    }
                    int i2 = i + 1;
                    char[] textArray2 = String.valueOf(game.player.currPokemon.maxStats.get(stat)).toCharArray();
                    int offset = 8 * (3 - textArray2.length);
                    for (char c : textArray2) {
                        game.uiBatch.draw(game.transparentDict.get(Character.valueOf(c)), (float) (120 + offset), (float) (128 - (8 * i2)));
                        offset += 8;
                    }
                    i = i2 + 1;
                }
                if (this.timer < 82) {
                    this.timer++;
                } else if (InputProcessor.aJustPressed) {
                    game.actionStack.remove(this);
                    game.insertAction(this.nextAction);
                }
            }
        }
    }
